package net.zoneland.knowledge.dao;

import net.zoneland.knowledge.controller.bean.RedBaseRouteQueryVo;
import net.zoneland.knowledge.controller.bean.RedRouteInfo;
import net.zoneland.knowledge.controller.bean.RedRouteInfoWithBlobs;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * 红色路线.
 */
@Mapper
public interface RedRouteMapper {

    /**
     * 查询路线.
     * @param condition 查询条件
     * @return 路线集合
     */
    @Select({
        "<script>",
        " SELECT AER.ID,AER.TITLE,AER.CMPNAME,AER.PATH_NAME,AER.RED_CULTURE_BASE_NANE ,AER.PATH_CONDITION",
        " FROM AITK_EXCHANGE_ROUTE AER",
        " WHERE 1 = 1 ",
        " <if test=\"cmpName != null and cmpName != ''\"> AND AER.CMPNAME=#{cmpName,jdbcType=VARCHAR} </if> ",
        " ORDER BY CMPNAME DESC ",
        "</script>"
    })
    @Results(id = "redRouteResultMap", value = {
        @Result(column = "ID", property = "id", jdbcType =  JdbcType.VARCHAR, id = true),
        @Result(column = "CMPNAME", property = "cmpName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "TITLE", property = "title", jdbcType = JdbcType.VARCHAR),
        @Result(column = "PATH_NAME", property = "pathName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "PATH_CONDITION", property = "pathCondition", jdbcType = JdbcType.VARCHAR),
        @Result(column = "RED_CULTURE_BASE_NANE", property = "redCultureBaseName", jdbcType = JdbcType.VARCHAR)
    })
    List<RedRouteInfo> search(final RedBaseRouteQueryVo condition);


    /**
     * 查询路线.
     * @param  id id
     * @return 路线
     */
    @Select({
        "<script>",
        "SELECT AER.ID, AER.TITLE, AER.CMPNAME, AER.PATH_NAME, AER.RED_CULTURE_BASE_NANE, AER.PATH_CONDITION," ,
        " AER.CONTACT, AER.CONTACT_PHONE, AER.PICTURE_NAME, AER.PICTURE_FILE, AER.PICTURE_EXPLAIN ",
        " from AITK_EXCHANGE_ROUTE AER",
        " WHERE 1 = 1 ",
        "<if test=\"id != null and id != ''\"> AND ID=#{id,jdbcType=VARCHAR} </if> " ,
        "</script>"
    })
    @Results(value = {
        @Result(column = "ID", property = "id", jdbcType =  JdbcType.VARCHAR, id = true),
        @Result(column = "CMPNAME", property = "cmpName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "TITLE", property = "title", jdbcType = JdbcType.VARCHAR),
        @Result(column = "PATH_NAME", property = "pathName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "PATH_CONDITION", property = "pathCondition", jdbcType = JdbcType.VARCHAR),
        @Result(column = "RED_CULTURE_BASE_NANE", property = "redCultureBaseName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "CONTACT", property = "contact", jdbcType = JdbcType.VARCHAR),
        @Result(column = "CONTACT_PHONE", property = "contactPhone", jdbcType = JdbcType.VARCHAR),
        @Result(column = "PICTURE_NAME", property = "pictureName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "PICTURE_FILE", property="pictureFile", jdbcType=JdbcType.BLOB),
        @Result(column = "PICTURE_EXPLAIN", property = "pictureExplain", jdbcType = JdbcType.VARCHAR)
    })
    RedRouteInfoWithBlobs searchById(final String id);

}
